<template>
  <el-dialog :visible.sync="currentShowFlag" append-to-body fullscreen :close-on-click-modal="false" :close-on-press-escape="false" @open="handleDialogOpen" @closed="handleDialogClosed">
    <div slot="title" class="detail-dialog__header">{{$t('balance_unlisted.pageTitle')}}</div>
    <el-tabs v-model="activeTabName">
      <el-tab-pane name="tab1" :label="this.$t('balance_unlisted.reform')">
        <simple-form :validate-info="{tabName: 'tab1' }" ref="form_0" :form-field="formField.form_0" v-model="formModel" labelPosition="top" :grid="{xs: 12, sm: 12, md: 6}" :view-flag="viewFlag"></simple-form>
        <simple-form-container :title="this.$t('balance_unlisted.busiandlevethree')">
          <simple-form :validate-info="{tabName: 'tab1' }" ref="form_1" :form-field="formField.form_1" v-model="formModel" labelPosition="top" :grid="{xs: 12, sm: 12, md: 6}" :view-flag="viewFlag"></simple-form>
        </simple-form-container>
        <simple-form :validate-info="{tabName: 'tab1' }" ref="form_2" :form-field="formField.form_2" v-model="formModel" labelPosition="top" :grid="{xs: 12, sm: 12, md: 6}" :view-flag="viewFlag"></simple-form>
        <simple-form-container :title="this.$t('balance_unlisted.unbusicharge')">
          <simple-form :validate-info="{tabName: 'tab1' }" ref="form_3" :form-field="formField.form_3" v-model="formModel" labelPosition="top" :grid="{xs: 12, sm: 12, md: 6}" :view-flag="viewFlag"></simple-form>
        </simple-form-container>
        <simple-form :validate-info="{tabName: 'tab2' }" ref="form_4" :form-field="formField.form_4" v-model="formModel" labelPosition="top" :grid="{xs: 12, sm: 12, md: 6}" :view-flag="viewFlag"></simple-form>
      </el-tab-pane>
      <el-tab-pane name="tab2" :label="this.$t('balance_unlisted.assetliabilitie')">
        <simple-form :validate-info="{tabName: 'tab2' }" ref="form_30" :form-field="formField.form_30" v-model="formModel" labelPosition="top" :grid="{xs: 12, sm: 12, md: 6}" :view-flag="viewFlag"></simple-form>
        <simple-form-container :title="this.$t('balance_unlisted.asset')">
          <simple-form :validate-info="{tabName: 'tab2' }" ref="form_5" :form-field="formField.form_5" v-model="formModel" labelPosition="top" :grid="{xs: 12, sm: 12, md: 6}" :view-flag="viewFlag"></simple-form>
        </simple-form-container>
        <simple-form-container :title="this.$t('balance_unlisted.liability')">
          <simple-form :validate-info="{tabName: 'tab2' }" ref="form_6" :form-field="formField.form_6" v-model="formModel" labelPosition="top" :grid="{xs: 12, sm: 12, md: 6}" :view-flag="viewFlag"></simple-form>
        </simple-form-container>
      </el-tab-pane>
      <el-tab-pane name="tab3" :label="this.$t('balance_unlisted.unminingareab')">
        <simple-form :validate-info="{tabName: 'tab4' }" ref="form_7" :form-field="formField.form_7" v-model="formModel" labelPosition="top" :grid="{xs: 12, sm: 12, md: 6}" :view-flag="viewFlag"></simple-form>
        <simple-form-container :title="this.$t('balance_unlisted.businessincome')">
          <simple-form :validate-info="{tabName: 'tab3' }" ref="form_8" :form-field="formField.form_8" v-model="formModel" labelPosition="top" :grid="{xs: 12, sm: 12, md: 6}" :view-flag="viewFlag"></simple-form>
        </simple-form-container>
        <simple-form-container :title="this.$t('balance_unlisted.cost')">
          <simple-form :validate-info="{tabName: 'tab3' }" ref="form_9" :form-field="formField.form_9" v-model="formModel" labelPosition="top" :grid="{xs: 12, sm: 12, md: 6}" :view-flag="viewFlag"></simple-form>
        </simple-form-container>
        <simple-form :validate-info="{tabName: 'tab3' }" ref="form_10" :form-field="formField.form_10" v-model="formModel" labelPosition="top" :grid="{xs: 12, sm: 12, md: 6}" :view-flag="viewFlag"></simple-form>
        <simple-form :validate-info="{tabName: 'tab4' }" ref="form_11" :form-field="formField.form_11" v-model="formModel" labelPosition="top" :grid="{xs: 12, sm: 12, md: 6}" :view-flag="viewFlag"></simple-form>
        <simple-form-container :title="this.$t('balance_unlisted.businessincome')">
          <simple-form :validate-info="{tabName: 'tab3' }" ref="form_12" :form-field="formField.form_12" v-model="formModel" labelPosition="top" :grid="{xs: 12, sm: 12, md: 6}" :view-flag="viewFlag"></simple-form>
        </simple-form-container>
        <simple-form-container :title="this.$t('balance_unlisted.cost')">
          <simple-form :validate-info="{tabName: 'tab3' }" ref="form_13" :form-field="formField.form_13" v-model="formModel" labelPosition="top" :grid="{xs: 12, sm: 12, md: 6}" :view-flag="viewFlag"></simple-form>
        </simple-form-container>
        <simple-form :validate-info="{tabName: 'tab3' }" ref="form_14" :form-field="formField.form_14" v-model="formModel" labelPosition="top" :grid="{xs: 12, sm: 12, md: 6}" :view-flag="viewFlag"></simple-form>
      </el-tab-pane>
      <el-tab-pane name="tab4" :label="this.$t('balance_unlisted.miningareabcurrentyear')">
        <simple-form :validate-info="{tabName: 'tab5' }" ref="form_23" :form-field="formField.form_23" v-model="formModel" labelPosition="top" :grid="{xs: 12, sm: 12, md: 6}" :view-flag="viewFlag"></simple-form>
        <simple-form :validate-info="{tabName: 'tab5' }" ref="form_15" :form-field="formField.form_15" v-model="formModel" labelPosition="top" :grid="{xs: 12, sm: 12, md: 6}" :view-flag="viewFlag"></simple-form>
        <simple-form :validate-info="{tabName: 'tab5' }" ref="form_16" :form-field="formField.form_16" v-model="formModel" labelPosition="top" :grid="{xs: 12, sm: 12, md: 6}" :view-flag="viewFlag"></simple-form>
        <simple-form-container :title="this.$t('balance_unlisted.extrevenue')">
          <simple-form :validate-info="{tabName: 'tab5' }" ref="form_17" :form-field="formField.form_17" v-model="formModel" labelPosition="top" :grid="{xs: 12, sm: 12, md: 6}" :view-flag="viewFlag"></simple-form>
        </simple-form-container>
        <simple-form :validate-info="{tabName: 'tab5' }" ref="form_18" :form-field="formField.form_18" v-model="formModel" labelPosition="top" :grid="{xs: 12, sm: 12, md: 6}" :view-flag="viewFlag"></simple-form>
        <simple-form :validate-info="{tabName: 'tab5' }" ref="form_19" :form-field="formField.form_19" v-model="formModel" labelPosition="top" :grid="{xs: 12, sm: 12, md: 6}" :view-flag="viewFlag"></simple-form>
        <simple-form :validate-info="{tabName: 'tab5' }" ref="form_20" :form-field="formField.form_20" v-model="formModel" labelPosition="top" :grid="{xs: 12, sm: 12, md: 6}" :view-flag="viewFlag"></simple-form>
        <simple-form :validate-info="{tabName: 'tab5' }" ref="form_21" :form-field="formField.form_21" v-model="formModel" labelPosition="top" :grid="{xs: 12, sm: 12, md: 6}" :view-flag="viewFlag"></simple-form>
        <simple-form :validate-info="{tabName: 'tab5' }" ref="form_22" :form-field="formField.form_22" v-model="formModel" labelPosition="top" :grid="{xs: 12, sm: 12, md: 6}" :view-flag="viewFlag"></simple-form>
      </el-tab-pane>
      <el-tab-pane name="tab5" :label="this.$t('balance_unlisted.thestaff')">
        <simple-form :validate-info="{tabName: 'tab5' }" ref="form_24" :form-field="formField.form_24" v-model="formModel" labelPosition="top" :grid="{xs: 12, sm: 12, md: 6}" :view-flag="viewFlag"></simple-form>
        <simple-form-container :title="this.$t('balance_unlisted.reduce')">
          <simple-form :validate-info="{tabName: 'tab5' }" ref="form_25" :form-field="formField.form_25" v-model="formModel" labelPosition="top" :grid="{xs: 12, sm: 12, md: 6}" :view-flag="viewFlag"></simple-form>
        </simple-form-container>
        <simple-form-container :title="this.$t('balance_unlisted.increase')">
          <simple-form :validate-info="{tabName: 'tab5' }" ref="form_26" :form-field="formField.form_26" v-model="formModel" labelPosition="top" :grid="{xs: 12, sm: 12, md: 6}" :view-flag="viewFlag"></simple-form>
        </simple-form-container>
        <simple-form :validate-info="{tabName: 'tab5' }" ref="form_27" :form-field="formField.form_27" v-model="formModel" labelPosition="top" :grid="{xs: 12, sm: 12, md: 6}" :view-flag="viewFlag"></simple-form>
        <simple-form-container :title="this.$t('balance_unlisted.currentemployeenum')">
          <simple-form :validate-info="{tabName: 'tab5' }" ref="form_28" :form-field="formField.form_28" v-model="formModel" labelPosition="top" :grid="{xs: 12, sm: 12, md: 6}" :view-flag="viewFlag"></simple-form>
        </simple-form-container>
        <simple-form :validate-info="{tabName: 'tab5' }" ref="form_29" :form-field="formField.form_29" v-model="formModel" labelPosition="top" :grid="{xs: 12, sm: 12, md: 6}" :view-flag="viewFlag"></simple-form>
      </el-tab-pane>
    </el-tabs>
    <div slot="footer">
      <el-button @click="handleDialogClose">{{viewFlag ? $t('operation.close') : $t('operation.cancel')}}</el-button>
      <el-button type="primary" @click="handleDataSubmit" v-if="!viewFlag">{{$t('operation.submit')}}</el-button>
    </div>
  </el-dialog>
</template>
<script>
const BASEURL = {
  save: '/Web/BizController/ajax.html?sys_method=Add&sys_objName=Biz_Unlisted_Custody_Business',
  update: '/Web/BizController/ajax.html?sys_method=Update&sys_objName=Biz_Unlisted_Custody_Business'
}
export default {
  name: 'balance_factory_detail',
  data () {
    return {
      activeTabName: 'tab1',
      formModel: {},
      calculate: {
        subtotalnonoperatingcost: ['repairreconstructioncost', 'assetimpairmentloss', 'resettlementcost'],
        totalassets: ['currencyfund', 'stocknetreceivables', 'netvalueoffixedassets', 'buildingassets', 'miningassets'],
        totalliabilities: ['shorttermnegativeinterest', 'assetsliabilities'],
        totalincomequarter: ['internalcompanyincomequarter', 'externalcompanyincomequarter'],
        totalincomeyear: ['internalcompanyincomeyear', 'externalcompanyincomeyear'],
        totalprofitquarter: ['totalincomequarter', 'totalcostquarter'],
        totalprofityear: ['totalincomeyear', 'totalcostyear'],
        totalincome: ['totalexternalincome', 'listedcompany', 'unlistedcompany'],
        totalexternalincome: ['socialincome', 'industrialserviceincome', 'landleaseandotherincome', 'incomingandoutgoing'],
        totalcostmining: ['laborcostmining', 'depreciationdepletionmining', 'othermining'],
        subtotalreduction: ['naturalreduction', 'agreementcancellation', 'specialtypeearlyretirement', 'transferlisted', 'otherreduction'],
        subtotalincrease: ['undergraduate', 'demobilizedserviceman', 'otherincrease'],
        totalcurrentemployee: ['contractemployeecurrent', 'marketemployeecurrent', 'laboremployeecurrent']
      }
    }
  },
  inject: ['handleDataSearch'],
  computed: {
    currentShowFlag: {
      get () { return this.showFlag },
      set (val) { this.$emit('update:showFlag', val) }
    },
    formField () {
      return {
        form_0: [
          {
            prop: 'companyname',
            label: this.$t('balance_unlisted.companyname'),
            type: 'Select',
            component: { optionList: this.extData.orgList.map(item => { return { key: item.value, value: item.value, text: item.text } }) },
            viewFlag: true
          },
          {
            prop: 'uploadyear',
            label: this.$t('balance_unlisted.uploadyear'),
            type: 'Input',
            viewFlag: true
          },
          {
            prop: 'uploadquarter',
            label: this.$t('balance_unlisted.uploadquarter'),
            type: 'Input',
            viewFlag: true
          }
        ],
        form_1: [
          {
            prop: 'bizcategory1',
            label: this.$t('balance_unlisted.bizcategory1'),
            type: 'Input',
            viewFlag: true
          },
          {
            prop: 'bizcategory2',
            label: this.$t('balance_unlisted.bizcategory2'),
            type: 'Input',
            viewFlag: true
          }
        ],
        form_2: [
          {
            prop: 'reformmethod',
            label: this.$t('balance_unlisted.reformmethod'),
            type: 'Select',
            component: { optionList: this.$getDictList('改革方式_未上市') },
            rules: { trigger: 'change', message: this.$t('validate.notSelect'), required: true }
          },
          {
            prop: 'totalprofit2015',
            label: this.$t('balance_unlisted.totalprofit2015'),
            type: 'NumberInput',
            rules: { trigger: 'blur', message: this.$t('validate.notBlank'), required: true }
          }
        ],
        form_3: [
          {
            prop: 'subtotalnonoperatingcost',
            label: this.$t('balance_unlisted.subtotalnonoperatingcost'),
            type: 'Input',
            viewFlag: true
          },
          {
            prop: 'repairreconstructioncost',
            label: this.$t('balance_unlisted.repairreconstructioncost'),
            type: 'NumberInput',
            rules: { trigger: 'blur', message: this.$t('validate.notBlank'), required: true },
            event: {
              change: this.subtotalnonoperatingcost
            }
          },
          {
            prop: 'assetimpairmentloss',
            label: this.$t('balance_unlisted.assetimpairmentloss'),
            type: 'NumberInput',
            rules: { trigger: 'blur', message: this.$t('validate.notBlank'), required: true },
            event: {
              change: this.subtotalnonoperatingcost
            }
          },
          {
            prop: 'resettlementcost',
            label: this.$t('balance_unlisted.resettlementcost'),
            type: 'NumberInput',
            rules: { trigger: 'blur', message: this.$t('validate.notBlank'), required: true },
            event: {
              change: this.subtotalnonoperatingcost
            }
          }
        ],
        form_4: [
          {
            prop: 'reformmeasuresprogress',
            label: this.$t('balance_unlisted.reformmeasuresprogress'),
            type: 'Input',
            rules: { trigger: 'blur', message: this.$t('validate.notBlank'), required: true }
          },
          {
            prop: 'existingproblem',
            label: this.$t('balance_unlisted.existingproblem'),
            type: 'Input',
            rules: { trigger: 'blur', message: this.$t('validate.notBlank'), required: true }
          }
        ],
        form_5: [
          {
            prop: 'totalassets',
            label: this.$t('balance_unlisted.totalassets'),
            type: 'NumberInput',
            rules: { trigger: 'blur', message: this.$t('validate.notBlank'), required: true },
            event: {
              change: this.assetsliabilities
            }
          },
          {
            prop: 'currencyfund',
            label: this.$t('balance_unlisted.currencyfund'),
            type: 'NumberInput',
            rules: { trigger: 'blur', message: this.$t('validate.notBlank'), required: true }
          },
          {
            prop: 'stocknetreceivables',
            label: this.$t('balance_unlisted.stocknetreceivables'),
            type: 'NumberInput',
            rules: { trigger: 'blur', message: this.$t('validate.notBlank'), required: true }
          },
          {
            prop: 'netvalueoffixedassets',
            label: this.$t('balance_unlisted.netvalueoffixedassets'),
            type: 'NumberInput',
            rules: { trigger: 'blur', message: this.$t('validate.notBlank'), required: true }
          },
          {
            prop: 'buildingassets',
            label: this.$t('balance_unlisted.buildingassets'),
            type: 'NumberInput',
            rules: { trigger: 'blur', message: this.$t('validate.notBlank'), required: true }
          },
          {
            prop: 'miningassets',
            label: this.$t('balance_unlisted.miningassets'),
            type: 'NumberInput',
            rules: { trigger: 'blur', message: this.$t('validate.notBlank'), required: true }
          }
        ],
        form_6: [
          {
            prop: 'totalliabilities',
            label: this.$t('balance_unlisted.totalliabilities'),
            type: 'NumberInput',
            rules: [
              { trigger: 'blur', message: this.$t('validate.notBlank'), required: true },
              {
                // 自定义校验规则
                trigger: 'blur',
                validator: this.totalliabilities
              }],
            event: {
              change: this.assetsliabilities
            }
          },
          {
            prop: 'shorttermnegativeinterest',
            label: this.$t('balance_unlisted.shorttermnegativeinterest'),
            type: 'NumberInput',
            rules: { trigger: 'blur', message: this.$t('validate.notBlank'), required: true }
          },
          {
            prop: 'assetsliabilities',
            label: this.$t('balance_unlisted.assetsliabilities'),
            type: 'Input',
            viewFlag: true
          }
        ],
        form_7: [
          { type: 'Title', title: this.$t('balance_unlisted.currentmonth'), col: { span: 24 } }
        ],
        form_8: [
          {
            prop: 'totalincomequarter',
            label: this.$t('balance_unlisted.totalincomequarter'),
            type: 'Input',
            viewFlag: true
          },
          {
            prop: 'internalcompanyincomequarter',
            label: this.$t('balance_unlisted.internalcompanyincomequarter'),
            type: 'NumberInput',
            rules: { trigger: 'blur', message: this.$t('validate.externalcompanyincomequarter'), required: true },
            event: {
              change: this.totalincomequarter
            }
          },
          {
            prop: 'externalcompanyincomequarter',
            label: this.$t('balance_unlisted.internalcompanyincomequarter'),
            type: 'NumberInput',
            rules: { trigger: 'blur', message: this.$t('validate.notBlank'), required: true },
            event: {
              change: this.totalincomequarter
            }
          }
        ],
        form_9: [
          {
            prop: 'totalcostquarter',
            label: this.$t('balance_unlisted.totalcostquarter'),
            type: 'NumberInput',
            rules: [
              { trigger: 'blur', message: this.$t('validate.notBlank'), required: true }],
            event: {
              change: this.totalprofitquarter
            }
          },
          {
            prop: 'laborcostquarter',
            label: this.$t('balance_unlisted.laborcostquarter'),
            type: 'NumberInput',
            rules: [
              { trigger: 'blur', message: this.$t('validate.notBlank'), required: true },
              {
                // 自定义校验规则
                trigger: 'blur',
                validator: this.laborcostquarter
              }
            ]
          },
          {
            prop: 'interestexpensequarter',
            label: this.$t('balance_unlisted.interestexpensequarter'),
            type: 'NumberInput',
            rules: [
              { trigger: 'blur', message: this.$t('validate.notBlank'), required: true }]
          },
          {
            prop: 'depreciationdepletionquarter',
            label: this.$t('balance_unlisted.depreciationdepletionquarter'),
            type: 'NumberInput',
            rules: [
              { trigger: 'blur', message: this.$t('validate.notBlank'), required: true }]
          }
        ],
        form_10: [
          {
            prop: 'totalprofitquarter',
            label: this.$t('balance_unlisted.totalprofitquarter'),
            type: 'Input',
            viewFlag: true
          }
        ],
        form_11: [
          { type: 'Title', title: this.$t('balance_unlisted.currentyear'), col: { span: 24 } }
        ],
        form_12: [
          {
            prop: 'totalincomeyear',
            label: this.$t('balance_unlisted.totalincomeyear'),
            type: 'Input',
            viewFlag: true
          },
          {
            prop: 'internalcompanyincomeyear',
            label: this.$t('balance_unlisted.internalcompanyincomeyear'),
            type: 'NumberInput',
            rules: { trigger: 'blur', message: this.$t('validate.notBlank'), required: true },
            event: {
              change: this.totalincomeyear
            }
          },
          {
            prop: 'externalcompanyincomeyear',
            label: this.$t('balance_unlisted.externalcompanyincomeyear'),
            type: 'NumberInput',
            rules: { trigger: 'blur', message: this.$t('validate.notBlank'), required: true },
            event: {
              change: this.totalincomeyear
            }
          }
        ],
        form_13: [
          {
            prop: 'totalcostyear',
            label: this.$t('balance_unlisted.totalcostyear'),
            type: 'NumberInput',
            rules: [
              { trigger: 'blur', message: this.$t('validate.notBlank'), required: true },
              {
                // 自定义校验规则
                trigger: 'blur',
                validator: this.totalcostyear
              }],
            event: {
              change: this.totalprofityear
            }
          },
          {
            prop: 'laborcostyear',
            label: this.$t('balance_unlisted.laborcostyear'),
            type: 'NumberInput',
            rules: [
              { trigger: 'blur', message: this.$t('validate.notBlank'), required: true }],
            event: {
              change: this.perlaborcost
            }
          },
          {
            prop: 'interestexpenseyear',
            label: this.$t('balance_unlisted.interestexpenseyear'),
            type: 'NumberInput',
            rules: [
              { trigger: 'blur', message: this.$t('validate.notBlank'), required: true }]
          },
          {
            prop: 'depreciationdepletionyear',
            label: this.$t('balance_unlisted.depreciationdepletionyear'),
            type: 'NumberInput',
            rules: [
              { trigger: 'blur', message: this.$t('validate.notBlank'), required: true }]
          }
        ],
        form_14: [
          {
            prop: 'totalprofityear',
            label: this.$t('balance_unlisted.totalprofityear'),
            type: 'Input',
            viewFlag: true
          }
        ],
        form_15: [
          { type: 'Title', title: this.$t('balance_unlisted.businessincome'), col: { span: 24 } }
        ],
        form_16: [
          {
            prop: 'totalincome',
            label: this.$t('balance_unlisted.totalincome'),
            type: 'Input',
            viewFlag: true
          }
        ],
        form_17: [
          {
            prop: 'totalexternalincome',
            label: this.$t('balance_unlisted.totalexternalincome'),
            type: 'Input',
            viewFlag: true
          },
          {
            prop: 'socialincome',
            label: this.$t('balance_unlisted.socialincome'),
            type: 'NumberInput',
            rules: { trigger: 'blur', message: this.$t('validate.notBlank'), required: true },
            event: {
              change: this.totalexternalincome
            }
          },
          {
            prop: 'industrialserviceincome',
            label: this.$t('balance_unlisted.industrialserviceincome'),
            type: 'NumberInput',
            rules: { trigger: 'blur', message: this.$t('validate.notBlank'), required: true },
            event: {
              change: this.totalexternalincome
            }
          },
          {
            prop: 'landleaseandotherincome',
            label: this.$t('balance_unlisted.landleaseandotherincome'),
            type: 'NumberInput',
            rules: { trigger: 'blur', message: this.$t('validate.notBlank'), required: true },
            event: {
              change: this.totalexternalincome
            }
          },
          {
            prop: 'incomingandoutgoing',
            label: this.$t('balance_unlisted.incomingandoutgoing'),
            type: 'NumberInput',
            rules: { trigger: 'blur', message: this.$t('validate.notBlank'), required: true },
            event: {
              change: this.totalexternalincome
            }
          }
        ],
        form_18: [
          {
            prop: 'listedcompany',
            label: this.$t('balance_unlisted.listedcompany'),
            type: 'NumberInput',
            rules: { trigger: 'blur', message: this.$t('validate.notBlank'), required: true },
            event: {
              change: this.totalincome
            }
          },
          {
            prop: 'unlistedcompany',
            label: this.$t('balance_unlisted.unlistedcompany'),
            type: 'NumberInput',
            rules: { trigger: 'blur', message: this.$t('validate.notBlank'), required: true },
            event: {
              change: this.totalincome
            }
          }
        ],
        form_19: [
          { type: 'Title', title: this.$t('balance_unlisted.nonoperatingincome'), col: { span: 24 } }
        ],
        form_20: [
          {
            prop: 'totalnonoperatingincome',
            label: this.$t('balance_unlisted.totalnonoperatingincome'),
            type: 'NumberInput',
            rules: { trigger: 'blur', message: this.$t('validate.notBlank'), required: true },
            event: {
              change: this.totalprofitmining
            }
          },
          {
            prop: 'groupsubsidy',
            label: this.$t('balance_unlisted.groupsubsidy'),
            type: 'NumberInput',
            rules: { trigger: 'blur', message: this.$t('validate.notBlank'), required: true }
          }
        ],
        form_21: [
          { type: 'Title', title: this.$t('balance_unlisted.cost'), col: { span: 24 } }
        ],
        form_22: [
          {
            prop: 'totalcostmining',
            label: this.$t('balance_unlisted.totalcostmining'),
            type: 'Input',
            viewFlag: true
          },
          {
            prop: 'laborcostmining',
            label: this.$t('balance_unlisted.laborcostmining'),
            type: 'NumberInput',
            rules: { trigger: 'blur', message: this.$t('validate.notBlank'), required: true },
            event: {
              change: this.laborcostmining
            }
          },
          {
            prop: 'depreciationdepletionmining',
            label: this.$t('balance_unlisted.depreciationdepletionmining'),
            type: 'NumberInput',
            rules: { trigger: 'blur', message: this.$t('validate.notBlank'), required: true },
            event: {
              change: this.totalcostmining
            }
          },
          {
            prop: 'othermining',
            label: this.$t('balance_unlisted.othermining'),
            type: 'NumberInput',
            rules: { trigger: 'blur', message: this.$t('validate.notBlank'), required: true },
            event: {
              change: this.totalcostmining
            }
          }
        ],
        form_23: [
          {
            prop: 'totalprofitmining',
            label: this.$t('balance_unlisted.totalprofitmining'),
            type: 'Input',
            viewFlag: true
          }
        ],
        form_24: [
          { type: 'Title', title: this.$t('balance_unlisted.currentyearchange'), col: { span: 24 } }
        ],
        form_25: [
          {
            prop: 'subtotalreduction',
            label: this.$t('balance_unlisted.subtotalreduction'),
            type: 'Input',
            viewFlag: true
          },
          {
            prop: 'naturalreduction',
            label: this.$t('balance_unlisted.naturalreduction'),
            type: 'NumberInput',
            rules: { trigger: 'blur', message: this.$t('validate.notBlank'), required: true },
            event: {
              change: this.subtotalreduction
            }
          },
          {
            prop: 'agreementcancellation',
            label: this.$t('balance_unlisted.agreementcancellation'),
            type: 'NumberInput',
            rules: { trigger: 'blur', message: this.$t('validate.notBlank'), required: true },
            event: {
              change: this.subtotalreduction
            }
          },
          {
            prop: 'specialtypeearlyretirement',
            label: this.$t('balance_unlisted.specialtypeearlyretirement'),
            type: 'NumberInput',
            rules: { trigger: 'blur', message: this.$t('validate.notBlank'), required: true },
            event: {
              change: this.subtotalreduction
            }
          },
          {
            prop: 'transferlisted',
            label: this.$t('balance_unlisted.transferlisted'),
            type: 'NumberInput',
            rules: { trigger: 'blur', message: this.$t('validate.notBlank'), required: true },
            event: {
              change: this.subtotalreduction
            }
          },
          {
            prop: 'otherreduction',
            label: this.$t('balance_unlisted.otherreduction'),
            type: 'NumberInput',
            rules: { trigger: 'blur', message: this.$t('validate.notBlank'), required: true },
            event: {
              change: this.subtotalreduction
            }
          }
        ],
        form_26: [
          {
            prop: 'subtotalincrease',
            label: this.$t('balance_unlisted.subtotalincrease'),
            type: 'Input',
            viewFlag: true
          },
          {
            prop: 'undergraduate',
            label: this.$t('balance_unlisted.undergraduate'),
            type: 'NumberInput',
            rules: { trigger: 'blur', message: this.$t('validate.notBlank'), required: true },
            event: {
              change: this.subtotalincrease
            }
          },
          {
            prop: 'demobilizedserviceman',
            label: this.$t('balance_unlisted.demobilizedserviceman'),
            type: 'NumberInput',
            rules: { trigger: 'blur', message: this.$t('validate.notBlank'), required: true },
            event: {
              change: this.subtotalincrease
            }
          },
          {
            prop: 'otherincrease',
            label: this.$t('balance_unlisted.otherincrease'),
            type: 'NumberInput',
            rules: { trigger: 'blur', message: this.$t('validate.notBlank'), required: true },
            event: {
              change: this.subtotalincrease
            }
          }
        ],
        form_27: [
          { type: 'Title', title: this.$t('balance_unlisted.currentyear'), col: { span: 24 } }
        ],
        form_28: [
          {
            prop: 'totalcurrentemployee',
            label: this.$t('balance_unlisted.totalcurrentemployee'),
            type: 'Input',
            viewFlag: true
          },
          {
            prop: 'contractemployeecurrent',
            label: this.$t('balance_unlisted.contractemployeecurrent'),
            type: 'NumberInput',
            rules: { trigger: 'blur', message: this.$t('validate.notBlank'), required: true },
            event: {
              change: this.totalcurrentemployee
            }
          },
          {
            prop: 'marketemployeecurrent',
            label: this.$t('balance_unlisted.marketemployeecurrent'),
            type: 'NumberInput',
            rules: { trigger: 'blur', message: this.$t('validate.notBlank'), required: true },
            event: {
              change: this.totalcurrentemployee
            }
          },
          {
            prop: 'laboremployeecurrent',
            label: this.$t('balance_unlisted.laboremployeecurrent'),
            type: 'NumberInput',
            rules: { trigger: 'blur', message: this.$t('validate.notBlank'), required: true },
            event: {
              change: this.totalcurrentemployee
            }
          }
        ],
        form_29: [
          {
            prop: 'perlaborcost',
            label: this.$t('balance_unlisted.perlaborcost'),
            type: 'Input',
            viewFlag: true
          }
        ],
        form_30: [
          { type: 'Title', title: this.$t('balance_unlisted.endTerm'), col: { span: 24 } }
        ]
      }
    }
  },
  props: {
    showFlag: { type: Boolean, default: false },
    viewFlag: { type: Boolean },
    detailData: { type: Object },
    extData: { type: Object }
  },
  methods: {
    handleDialogClose () {
      this.currentShowFlag = false
    },
    handleDataSubmit () {
      Promise.all(
        Object.keys(this.formField).map(key => {
          return this.$refs[key].validate()
        })
      )
        .then(resp => {
          let loadingFlag = this.$loading({ target: this.$el.querySelector('.el-dialog') })
          let submitModel = this.$_.cloneDeep(this.formModel)
          Object.assign(submitModel, { sys_mid: this.extData.sys_mid })
          this.$axios
            .post(this.detailData.id ? BASEURL.update : BASEURL.save, submitModel)
            .then(resp => {
              this.currentShowFlag = false
              this.$message({ type: 'success', message: this.$t('tip.saveSuccess') })
              this.handleDataSearch()
            })
            .finally(() => {
              loadingFlag.close()
            })
        })
        .catch(err => {
          // 跳转到未通过校验的tab，参数是simple-form的validate-info属性传入的
          this.activeTabName = err.tabName
        })
    },
    handleDialogOpen () {
      this.formModel = Object.assign({}, this.formModel, this.$_.cloneDeep(this.detailData))
    },
    handleDialogClosed () {
      Object.keys(this.formField).forEach(key => {
        this.$refs[key].resetFields()
      })
      this.formModel = {}
      this.activeTabName = 'tab1'
    },
    calculatesometotal (key) {
      let total = 0
      for (let item of this.calculate[key]) {
        total += Number(this.formModel[item]) || 0
      }
      this.$nextTick(() => {
        this.$set(this.formModel, key, total)
        // 设置本月数利润总额
        if (key === 'totalincomequarter') {
          this.calculatesub('totalprofitquarter')
        } else if (key === 'totalincomeyear') {
          this.calculatesub('totalprofityear')
        } else if (key === 'totalexternalincome') {
          this.calculatesometotal('totalincome')
        } else if (key === 'totalincome' || key === 'totalcostmining') {
          this.totalprofitmining()
        } else if (key === 'totalcurrentemployee') {
          this.perlaborcost()
        }
      })
    },
    calculatesub (key) {
      this.$nextTick(() => {
        let total = (Number(this.formModel[this.calculate[key][0]]) || 0) - (Number(this.formModel[this.calculate[key][1]]) || 0)
        this.$set(this.formModel, key, total)
      })
    },
    subtotalnonoperatingcost () {
      this.calculatesometotal('subtotalnonoperatingcost')
    },
    totalassets () {
      this.calculatesometotal('totalassets')
    },
    totalincomequarter () {
      this.calculatesometotal('totalincomequarter')
    },
    totalincomeyear () {
      this.calculatesometotal('totalincomeyear')
    },
    totalincome () {
      this.calculatesometotal('totalincome')
    },
    totalexternalincome () {
      this.calculatesometotal('totalexternalincome')
    },
    totalcostmining () {
      this.calculatesometotal('totalcostmining')
    },
    laborcostmining () {
      this.calculatesometotal('totalcostmining')
      this.perlaborcost()
    },
    subtotalreduction () {
      this.calculatesometotal('subtotalreduction')
    },
    subtotalincrease () {
      this.calculatesometotal('subtotalincrease')
    },
    totalcurrentemployee () {
      this.calculatesometotal('totalcurrentemployee')
    },
    totalprofitmining () {
      let total = (Number(this.formModel.totalincome) || 0) +
        (Number(this.formModel.totalnonoperatingincome) || 0) -
        (Number(this.formModel.totalcostmining) || 0)
      this.$nextTick(() => {
        this.$set(this.formModel, 'totalprofitmining', total)
      })
    },
    perlaborcost () {
      let total = (Number(this.formModel.laborcostyear) || 0) +
        (Number(this.formModel.laborcostmining) || 0)
      total = total / (Number(this.formModel.totalcurrentemployee) || 0)
      this.$nextTick(() => {
        this.$set(this.formModel, 'perlaborcost', total.toFixed(2))
      })
    },
    assetsliabilities () {
      let total = (Number(this.formModel.totalliabilities) / Number(this.formModel.totalassets)).toFixed(2)
      this.$nextTick(() => {
        this.$set(this.formModel, 'assetsliabilities', total)
      })
    },
    laborcostquarter (rule, value, callback) {
      if (Number(this.formModel.laborcostquarter) <
        (Number(this.formModel.interestexpensequarter) || 0) +
        (Number(this.formModel.depreciationdepletionquarter) || 0)) {
        callback(new Error('必须大于等于 利息支出 + 折旧折耗'))
      } else {
        callback()
      }
    },
    totalcostyear (rule, value, callback) {
      this.$nextTick(() => {
        let total = (Number(this.formModel.laborcostyear) || 0) + (Number(this.formModel.interestexpenseyear) || 0) + (Number(this.formModel.interestexpenseyear) || 0)
        if (Number(this.formModel.totalcostyear) < total) {
          callback(new Error('必须大于等于 人工成本 + 利息支出 + 折旧折耗'))
        } else {
          callback()
        }
      })
    },
    totalliabilities (rule, value, callback) {
      this.$nextTick(() => {
        let total = (Number(this.formModel.shorttermnegativeinterest) || 0) + (Number(this.formModel.assetsliabilities) || 0)
        if (Number(this.formModel.totalliabilities) < total) {
          callback(new Error('必须大于等于 短期负息资金 + 资产负债率'))
        } else {
          callback()
        }
      })
    },
    totalprofitquarter () {
      this.calculatesub('totalprofitquarter')
    },
    totalprofityear () {
      this.calculatesub('totalprofityear')
    }
  }
}
</script>
